package com.example.combwyaq.interceptor;

import android.util.Log;

import com.blankj.utilcode.util.SPStaticUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
/**
 * 针对接口中token限定的拦截器,
 * 像每个接口中的请求头添加token
 * */
public class TokenInterceptor implements Interceptor {
    private static final String TAG = "yqs";

    @Override
    public Response intercept(Chain chain) throws IOException {
        Log.i(TAG, "intercept: ");
        //先获取原有Request
        Request oldRequest = chain.request();
        //配置添加过token的Request
        Request.Builder builder = new Request.Builder();
        builder.url(oldRequest.url());
        builder.headers(oldRequest.headers());
        builder.header("token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI4NjMwNjQxOTY1NTcwMjEiLCJleHAiOjMyNDI0ODEyODQsImlhdCI6MTYyMTI0MDY0Mn0.7k0hgcBD-Xiif8zooxHIzSxlvN6H-IMhKttIt5yapAg");
        builder.post(oldRequest.body());
        Request request = builder.build();
        return chain.proceed(request);
    }
}
